package com.itcast.n1_内存调优;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: jvm
 * @description:
 * @author: flyduck
 * @create: 2024-10-16 16:24
 **/
public class Test09_内存遗漏问题2_匿名内部类在静态方法中创建不会持有调用者对象不会导致内存泄漏 {
    public static void main(String[] args) throws IOException {
        System.in.read();
        int count = 0;
        ArrayList<Object> objects = new ArrayList<>();
        while (true) {
            System.out.println(++count);
            objects.add(Outer6.newList());
        }
    }
}

class Outer6{
    private byte[] bytes = new byte[1024 * 1024];
    public static List<String> newList(){
        List<String> list = new ArrayList<String>(){{
           add("1");
           add("2");
        }};
        return list;
    }
}
